# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=asciidoc
pkgver=8.6.10
pkgrel=1
pkgdesc='Text document format for short documents, articles, books and UNIX man pages.'
arch=('any')
url='http://www.methods.co.nz/asciidoc/'
license=('GPL')
depends=('python2' 'libxslt' 'docbook-xsl')
makedepends=('tar')
groups=('base-devel')
# optdepends=('lilypond: music-filter'
            # 'imagemagick: music-filter (used in conjunction with lilypond)'
            # 'source-highlight: source-highlight-filter'
            # 'dblatex: pdf generation'
            # 'fop: alternative pdf generation'
            # 'lynx: text generation'
            # 'w3m: text generation (alternative to lynx)')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/asciidoc/asciidoc/archive/${pkgver}.tar.gz"
        0001-W32-confdir.msys2.patch)
noextract=("${pkgname}-${pkgver}.tar.gz")
sha256sums=('9e52f8578d891beaef25730a92a6e723596ddbd07bfe0d2a56486fcf63a0b983'
            '71f44b513f627b133afead38576fcb8a5460d0514174a4ce219c6ea761d8b40c')

prepare() {
  tar -xzvf ${pkgname}-${pkgver}.tar.gz --recursive-unlink

  cd ${pkgname}-${pkgver}

  patch -p1 -i ${srcdir}/0001-W32-confdir.msys2.patch

  # python2 fix
  for file in asciidocapi.py a2x.py asciidoc.py filters/music/music2png.py filters/latex/latex2img.py \
    filters/code/code-filter.py filters/graphviz/graphviz2png.py; do
  sed -i 's_#!/usr/bin/env python2_#!/usr/bin/python2_' $file
  done

  sed -i -e 's#python a2x.py#python2 a2x.py#' Makefile.in
}

build() {
  cd ${pkgname}-${pkgver}

  autoreconf -fi

  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc
}

package() {
  cd ${pkgname}-${pkgver}

  make install DESTDIR=${pkgdir}

  install -Dm644 asciidocapi.py \
    ${pkgdir}/usr/lib/python2.7/site-packages/asciidocapi.py

  install -Dm644 vim/syntax/asciidoc.vim \
    ${pkgdir}/usr/share/vim/vimfiles/syntax/asciidoc.vim
}
